package com.gin.no_gay_alliance.fragment.config;

import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.CompoundButton;

import com.gin.no_gay_alliance.activity.ReplyHistoryConfigActivity;
import com.gin.no_gay_alliance.activity.ReplyHistoryScanActivity;
import com.gin.no_gay_alliance.activity.ReplyHistorySearchActivity;
import com.gin.no_gay_alliance.databinding.FragmentConfigAdvancedFunctionBinding;
import com.gin.no_gay_alliance.fragment.base.BaseBindingFragment;
import com.gin.no_gay_alliance.utils.BuglyUtils;
import com.gin.no_gay_alliance.utils.ViewUtils;

/**
 * 高级功能
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/16 16:38
 **/
public class ConfigAdvancedFunctionFragment extends BaseBindingFragment<FragmentConfigAdvancedFunctionBinding> implements CompoundButton.OnCheckedChangeListener {
    /**
     * onCreateView 的后续操作
     */
    @Override
    protected void onCreateView() {
        ViewUtils.setOnClickListener(this, b.tvReplyHistoryConfig, b.tvReplyHistorySearch, b.tvReplyHistoryScan);

        b.swBuglySdk.setChecked(BuglyUtils.hasPermission());
        b.swBuglySdk.setOnCheckedChangeListener(this);
        b.tvLinkBuglySdk.setText(Html.fromHtml(BuglyUtils.HTML, Html.FROM_HTML_MODE_COMPACT));
        b.tvLinkBuglySdk.setMovementMethod(LinkMovementMethod.getInstance());
    }

    /**
     * 点击事件统一处理
     *
     * @param v 被点击的View
     */
    @Override
    public void onClick(View v) {
        // 配置
        if (v == b.tvReplyHistoryConfig) {
            ReplyHistoryConfigActivity.startActivity(requireContext());
        }
        // 搜索
        if (v == b.tvReplyHistorySearch) {
            ReplyHistorySearchActivity.startActivity(requireContext());
        }
        // 扫描
        if (v == b.tvReplyHistoryScan) {
            ReplyHistoryScanActivity.startActivity(requireContext());
        }
        super.onClick(v);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView == b.swBuglySdk) {
            BuglyUtils.setHasPermission(isChecked);
        }
    }
}
